package com.vehicle.common.service.datasource;

/**
 * Created by yantingbin on 2017/7/7.
 */
public final class DynamicDataSourceHolder {
    private static final ThreadLocal<DynamicDataSourceGlobal> DYNAMIC_DATA_SOURCE_GLOBAL_THREAD_LOCAL = new ThreadLocal<>();

    private DynamicDataSourceHolder() {

    }

    public static void putDataSource(DynamicDataSourceGlobal dataSource){
       DYNAMIC_DATA_SOURCE_GLOBAL_THREAD_LOCAL.set(dataSource);
    }

    public static DynamicDataSourceGlobal getDataSource(){
       return DYNAMIC_DATA_SOURCE_GLOBAL_THREAD_LOCAL.get();
    }

    public static void clearDataSource(){
        DYNAMIC_DATA_SOURCE_GLOBAL_THREAD_LOCAL.remove();
    }
}
